home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AnswerShell.c
-
- Contains: shell for MoreOpenAndSaveDemo
-
- Written by: Pete Gontier
-
- Copyright: Copyright (c) 1997-1998 Apple Computer, Inc.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
-
- <10> 2/12/99 PCG more sensible DebugStr message for case in which StandardGetFile
- fitler is passed a directory
- <9> 2/9/99 PCG QDGlobals
- <8> 1/22/99 PCG TARGET_CARBON and more test cases
- <7> 1/18/99 PCG better QuickTime support
- <6> 1/18/99 PCG more Put customization support
- <5> 1/7/99 PCG starting: call Standard FIle when Nav is not avail and dialog
- hook support
- <4> 7/27/98 PCG remove warnings re: missing params because Quinn treats warnings
- as errors
- <3> 7/24/98 PCG remove #include "MoveableModalDialog.h"
- <2> 7/11/98 PCG add header
- */
-
-
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #include "MoreOpenAndSave.h"
- #include "MoreDialogs.h"
- #include "MoreToolbox.h"
-
- #include <TextUtils.h>
- #include <Sound.h>
-
- enum
- {
- kResID_Base = 128,
- kResID_DialogItemList_CustomGetFile = kResID_Base,
- kResID_DialogItemList_CustomPutFile = kResID_DialogItemList_CustomGetFile,
- kResID_DialogItemList_MainWindow
- };
-
- static pascal Boolean CustomFileFilterProc (CInfoPBPtr cipbp, void *)
- {
- Boolean dropIt = false;
-
- if (!(cipbp->hFileInfo.ioFlAttrib & ioDirMask))
- if (cipbp->hFileInfo.ioFlFndrInfo.fdCreator != 'CWIE')
- dropIt = true;
-
- return dropIt;
- }
-
- static pascal Boolean StandardFileFilterProc (CInfoPBPtr cipbp)
- {
- Boolean dropIt = false;
-
- //
- // File filters for StandardGetFile should never be asked
- // to filter directories. We test here for that problem.
- //
-
- if (cipbp->hFileInfo.ioFlAttrib & ioDirMask)
- DebugStr ("\pA directory has been passed to the Standard File filter.");
- else if (cipbp->hFileInfo.ioFlFndrInfo.fdCreator != 'CWIE')
- dropIt = true;
-
- return dropIt;
- }
-
- static pascal Boolean ModalFilterYDProc (DialogPtr, EventRecord *event, short *, void *)
- {
- if (event->what) SysBeep (-1);
- return false;
- }
-
- static pascal DialogItemIndex DialogHookYDProc (DialogItemIndex index, DialogPtr dialog, void *)
- {
- static const SInt16 kCustomItemCount = 2;
-
- if (index >= 1 && index <= kCustomItemCount)
- (void) ToggleDialogCheckBox (dialog, index + MOASI_GetFirstCustomItemIndex ( ));
- else
- {
- /*
- Str15 message;
- NumToString (index,message);
- DebugStr (message);
- */
- }
-
- return index;
- }
-
- static pascal OSErr MyStandardGetFile (void)
- {
- OSErr err = noErr;
-
- FileFilterUPP upp = NewFileFilterProc (StandardFileFilterProc);
-
- if (!upp)
- err = MemError ( );
- else
- {
- StandardFileReply sfr;
- SFTypeList sft = { 'TEXT' };
-
- err = MOASI_StandardGetFile (upp,1,sft,&sfr);
-
- DisposeRoutineDescriptor (upp);
-
- if (!err && sfr.sfGood)
- {
- err = FSMakeFSSpec (sfr.sfFile.vRefNum, sfr.sfFile.parID, sfr.sfFile.name, &(sfr.sfFile));
- // we do this just to verify we have some semblance of valid data
- }
- }
-
- return err;
- }
-
- static pascal OSErr MyStandardGetFilePreview (void)
- {
- OSErr err = noErr;
-
- FileFilterUPP upp = NewFileFilterProc (StandardFileFilterProc);
-
- if (!upp)
- err = MemError ( );
- else
- {
- StandardFileReply sfr;
- SFTypeList sft = { 'TEXT' };
-
- err = MOASI_StandardGetFilePreview (upp,1,sft,&sfr);
-
- DisposeRoutineDescriptor (upp);
-
- if (!err && sfr.sfGood)
- {
- err = FSMakeFSSpec (sfr.sfFile.vRefNum, sfr.sfFile.parID, sfr.sfFile.name, &(sfr.sfFile));
- // we do this just to verify we have some semblance of valid data
- }
- }
-
- return err;
- }
-
- static pascal OSErr MyStandardOpenDialog (void)
- {
- StandardFileReply reply;
-
- return MOASI_StandardOpenDialog (&reply);
- }
-
- static pascal OSErr MyStandardPutFile (void)
- {
- StandardFileReply reply;
-
- return MOASI_StandardPutFile ("\pPrompt","\pDefaultFileName",&reply);
- }
-
- static pascal OSErr MyCustomGetFile (void)
- {
- OSErr err = noErr;
-
- FileFilterYDUPP fileFilterUPP = NewFileFilterYDProc (CustomFileFilterProc);
-
- if (!fileFilterUPP)
- err = MemError ( );
- else
- {
- ModalFilterYDUPP eventFilterUPP = NewModalFilterYDProc (ModalFilterYDProc);
-
- if (!eventFilterUPP)
- err = MemError ( );
- else
- {
- DlgHookYDUPP yduppDialogHook = NewDlgHookYDProc (DialogHookYDProc);
-
- if (!yduppDialogHook)
- err = MemError ( );
- else
- {
- StandardFileReply sfr;
- SFTypeList sft = { 'TEXT' };
- void *context = nil;
-
- err = MOASI_CustomGetFile (fileFilterUPP,1,sft,&sfr,kResID_DialogItemList_CustomGetFile,yduppDialogHook,eventFilterUPP,context);
-
- DisposeRoutineDescriptor (yduppDialogHook);
- }
- DisposeRoutineDescriptor (eventFilterUPP);
- }
- DisposeRoutineDescriptor (fileFilterUPP);
- }
-
- return err;
- }
-
- static pascal OSErr MyCustomGetFilePreview (void)
- {
- OSErr err = noErr;
-
- FileFilterYDUPP fileFilterUPP = NewFileFilterYDProc (CustomFileFilterProc);
-
- if (!fileFilterUPP)
- err = MemError ( );
- else
- {
- ModalFilterYDUPP eventFilterUPP = NewModalFilterYDProc (ModalFilterYDProc);
-
- if (!eventFilterUPP)
- err = MemError ( );
- else
- {
- DlgHookYDUPP yduppDialogHook = NewDlgHookYDProc (DialogHookYDProc);
-
- if (!yduppDialogHook)
- err = MemError ( );
- else
- {
- StandardFileReply sfr;
- SFTypeList sft = { 'TEXT' };
- void *context = nil;
-
- err = MOASI_CustomGetFilePreview (fileFilterUPP,1,sft,&sfr,kResID_DialogItemList_CustomGetFile,yduppDialogHook,eventFilterUPP,context);
-
- DisposeRoutineDescriptor (yduppDialogHook);
- }
- DisposeRoutineDescriptor (eventFilterUPP);
- }
- DisposeRoutineDescriptor (fileFilterUPP);
- }
-
- return err;
- }
-
- static pascal OSErr MyCustomPutFile (void)
- {
- OSErr err = noErr;
-
- ModalFilterYDUPP eventFilterUPP = NewModalFilterYDProc (ModalFilterYDProc);
-
- if (!eventFilterUPP)
- err = MemError ( );
- else
- {
- DlgHookYDUPP yduppDialogHook = NewDlgHookYDProc (DialogHookYDProc);
-
- if (!yduppDialogHook)
- err = MemError ( );
- else
- {
- StandardFileReply sfr;
- SFTypeList sft = { 'TEXT' };
-
- err = MOASI_CustomPutFile ("\pPrompt","\pDefaultFileName",&sfr,kResID_DialogItemList_CustomPutFile,yduppDialogHook,eventFilterUPP,nil);
-
- DisposeRoutineDescriptor (yduppDialogHook);
- }
- DisposeRoutineDescriptor (eventFilterUPP);
- }
-
- return err;
- }
-
- static pascal Boolean ModalFilterProc (DialogRef dialog, EventRecord *event, short *itemHit)
- {
- return StdFilterProc (dialog,event,itemHit);
- }
-
- void main (void)
- {
- if (InitMac ( ))
- SysBeep (-1);
- else
- {
- DialogRef dlgRef = GetNewDialog (129,nil,(WindowRef)-1);
- if (dlgRef)
- {
- ModalFilterUPP modalFilterUPP = NewModalFilterProc (ModalFilterProc);
- if (modalFilterUPP)
- {
- enum
- {
- kDialogItemIndex_PushButton_Quit = kStdOkItemIndex,
- kDialogItemIndex_PushButton_StandardGetFile,
- kDialogItemIndex_PushButton_StandardPutFile,
- kDialogItemIndex_PushButton_StandardOpenFile,
- kDialogItemIndex_PushButton_CustomGetFile,
- kDialogItemIndex_PushButton_CustomPutFile,
- kDialogItemIndex_PushButton_StandardGetFilePreview,
- kDialogItemIndex_PushButton_CustomGetFilePreview,
- kDialogItemIndex_CheckBox_ForceStandardFile
- };
-
- short itemHit;
-
- SetDialogDefaultItem (dlgRef,kDialogItemIndex_PushButton_Quit);
- SetDialogTracksCursor (dlgRef,true);
-
- #if TARGET_CARBON
-
- //
- // Standard File doesn't exist in Carbon,
- // so remove the check-box which would force
- // us to use it (kDialogItemIndex_CheckBox_ForceStandardFile).
- //
-
- ShortenDITL (dlgRef,1);
- #endif
-
- do
- {
- OSErr err = noErr;
-
- MoveableModalDialog (modalFilterUPP,&itemHit);
-
- switch (itemHit)
- {
-
- #if !TARGET_CARBON
- case kDialogItemIndex_CheckBox_ForceStandardFile :
-
- (void) MOASI_EnableDisableNav (!ToggleDialogCheckBox (dlgRef,kDialogItemIndex_CheckBox_ForceStandardFile));
- break;
- #endif
-
- case kDialogItemIndex_PushButton_StandardGetFilePreview :
-
- err = MyStandardGetFilePreview ( );
- break;
-
- case kDialogItemIndex_PushButton_CustomGetFilePreview :
-
- err = MyCustomGetFilePreview ( );
- break;
-
- case kDialogItemIndex_PushButton_StandardGetFile :
-
- err = MyStandardGetFile ( );
- break;
-
- case kDialogItemIndex_PushButton_StandardPutFile :
-
- err = MyStandardPutFile ( );
- break;
-
- case kDialogItemIndex_PushButton_StandardOpenFile :
-
- err = MyStandardOpenDialog ( );
- break;
-
- case kDialogItemIndex_PushButton_CustomGetFile :
-
- err = MyCustomGetFile ( );
- break;
-
- case kDialogItemIndex_PushButton_CustomPutFile :
-
- err = MyCustomPutFile ( );
- break;
- }
-
- if (err) SysBeep (-1);
- }
- while (itemHit != kDialogItemIndex_PushButton_Quit);
-
- DisposeRoutineDescriptor (modalFilterUPP);
- }
- DisposeDialog (dlgRef);
- }
- }
- }
-